<!DOCTYPE html>
<meta charset="utf-8">
<script src="/bower_components/webcomponentsjs/webcomponents-loader.js"></script>
<script src="/bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="/bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="/elements/som-rev-range/som-rev-range.html">
<test-fixture id="basic">
  <template>
    <som-rev-range></som-rev-range>
  </template>
</test-fixture>
<script>
(function() {
  'use strict';

  suite('basic tests', function() {
    var element;

    setup(function() {
      element = fixture('basic');
    });

    test('renders basic', function(done) {
      element.range = {
        positions: [
          "refs/heads/master@{#398901}",
          "refs/heads/master@{#398913}",
          "refs/heads/master@{#398921}",
          "refs/heads/master@{#398942}",
          "refs/heads/master@{#398946}"
        ],
        revisions: ["1a2b3c4d", "2a2b3c4d", "3a2b3c4d", "4a2b3c4d"],
        repo: "chromium",
      };

      flush(() => {
        assert(element.shadowRoot.querySelector('div').textContent.includes('398901 - 398946'))
        done();
      });
    });

    test('out-of-order commit positions', function(done) {
      element.range = {
        positions: [
          "refs/heads/master@{#398913}",
          "refs/heads/master@{#398921}",
          "refs/heads/master@{#398946}",
          "refs/heads/master@{#398942}",
          "refs/heads/master@{#398901}",
        ],
        revisions: ["1a2b3c4d", "2a2b3c4d", "3a2b3c4d", "4a2b3c4d"],
        repo: "chromium",
      };

      flush(() => {
        assert(element.shadowRoot.querySelector('div').textContent.includes('398901 - 398946'))
        done();
      });
    });

    test('revisions used instead of positions', function(done) {
      element.range = {
        repo: 'chromeos/fakerepo',
        revisions: ['abc123456789', 'abd223456789', 'abe323456789', 'abf423456789'],
        host: 'https://some-host.googlesource.com',
      };

        flush(() => {
          assert(element.shadowRoot.querySelector('div').textContent.includes('abc1234 - abf4234'));
        done();
      });
    });

    test('test regressionRangeLink positions', function(done) {
      element.range = {
        positions: [
          "refs/heads/master@{#398913}",
          "refs/heads/master@{#398921}",
          "refs/heads/master@{#398946}",
          "refs/heads/master@{#398942}",
          "refs/heads/master@{#398901}"
        ],
        revisions: ['abc123456789', 'abd223456789', 'abe323456789', 'abf423456789'],
        repo: "chromium",
      };

      flush(() => {
        const actualLink = element._regressionRangeLink(element.range)
        assert.equal(
          actualLink,
            'https://test-results.appspot.com/revision_range?start=398901&end=398946');
          done();
      });
    });

    test('test regressionRangeLink using revisions', function(done) {
      element.range = {
        repo: 'chromeos/fakerepo',
        revisions:  ['abc123456789', 'abd223456789', 'abe323456789', 'abf423456789'],
        host: 'https://some-host.googlesource.com',
      };

      flush(() => {
        const actualLink = element._regressionRangeLink(element.range)
        assert.equal(
          actualLink,
          'https://some-host.googlesource.com/chromeos/fakerepo/+log/' +
                'abc123456789^..abf423456789');
        done();
      });
    });
  });
})();
</script>
